<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 800px;
            height: 600px;
            border: 1px solid blue;
        }
        /* 1. 利用padding相对于父元素width的特质 */
        .squre1 {
            width: 20%;
            height: 0;
            padding-top: 20%;
            background-color: red;
        }
    </style>
</head>

<body>
    <h1>实现一个宽高自适应的正方形</h1>
    <div class="box">
        <div class="squre1"></div>
    </div>

</body>

</html>